// Header File
// Created 11/19/2007; 6:28:03 PM

#ifndef __GLOBALS_H__
#define __GLOBALS_H__

// Main include for TI files
#include <tigcclib.h>

// For debug purposes
//#define DEBUG 1
//#define HEAPTRACK 1

// Version string
const int VERSION = 73;
const char version[7] = "v0.7.3";

// C++ type bool
typedef unsigned char bool;
#define true  1
#define false 0

#ifndef INSTALL

// For debug purposes only
#ifdef DEBUG
	#define DebugStr(X) ClrScr(); DrawStr(1, 45, X, A_NORMAL); ngetchx();
	#define DebugInt(X) { char X_To_Str[10]; sprintf(X_To_Str, "%d", (X)); DebugStr(X_To_Str); }
	#define DebugStrNoPause(X) ClrScr(); DrawStr(1, 45, X, A_NORMAL);
	#define DebugIntNoPause(X) { char X_To_Str[10]; sprintf(X_To_Str, "%d", (X)); DebugStrNoPause(X_To_Str); }
#else
	#define DebugStr(X) ;
	#define DebugInt(X) ;
	#define DebugStrNoPause(X) ;
	#define DebugIntNoPause(X) ;
#endif

// Checks to see if allocations was complete, otherwise it crashes
#define AssertAllocate(X) if((X) == NULL) Crash(MEMORY, #X)

// Used to delete and reset a pointer
#define Delete(X) if(X != NULL) { Free(X); X = NULL; }

// Used for tracking the amount allocated and freed
#ifdef HEAPTRACK
	#define Malloc(X) _Malloc(X, #X)
	extern long int allocation;
	void *_Malloc(long int x, const char *title)
	{
		allocation += x;
		
		char str[20];
		sprintf(str, "%ld/%ld", x, allocation);
		ClrScr();
		DrawStr(1, 45, str, A_NORMAL);
		DrawStr(1, 55, title, A_NORMAL);
		ngetchx();

		long int *ptr = (long int*)malloc(x+sizeof(long int));
		ptr[0] = x;
		return ptr + 1;
	}
	#define Free(X) _Free((long int*)X, #X)
	void _Free(long int *ptr, const char *title)
	{
		ptr--;
		allocation -= ptr[0];
		
		char str[20];
		sprintf(str, "%ld/%ld", ptr[0], allocation);
		ClrScr();
		DrawStr(1, 45, str, A_NORMAL);
		DrawStr(1, 55, title, A_NORMAL);
		ngetchx();
		
		free(ptr);
	}
#else
	#define Malloc(size) malloc(size)
	#define Free(ptr) free(ptr)
#endif

#endif // !INSTALL

#endif
